GIT 变基

* 02f7168 (HEAD, master) add autorestart
| * 8138be4 (hotfix) bug fix
|/
……………………
………….
…….
..

以上为分支。需要把补丁变基到02f7168 之后使提交记录更简洁。

[book@SERVER realsync]$ git co hotfix
Switched to branch 'hotfix'

把hotfix 变基到master 之后。使master成为hotfix 的父提交。
但发现master 分支未和hotfix 合并

[book@SERVER realsync]$ git rebase master 



* 7a377fe (HEAD, hotfix) bug fix
* 02f7168 (master) add autorestart
……………………
………….
…….
..
Checkout master 分支
[book@SERVER realsync]$ git co master 
Switched to branch 'master'
[book@SERVER realsync]$ git merge hotfix

最后变基完成。

1.1. 变基例子:

如果先要把modify的修改应用到master 分支上。 因为hotfix 分支还不稳定。

git rebase --onto master modify hotfix

合并后图示

[book@SERVER scripts_new]$ git co master 
Switched to branch 'master'
[book@SERVER scripts_new]$ git merge hotfix

修改后示意图:

1.2. 如果需要把server 分支变基合并:

前面分支为master 分支,后边分支为需要变基的分支。

git rebase [basebranch] [topicbranch]
git rebase master modify

变基之后的图片:

示意图:

[book@SERVER scripts_new]$ git co master 
Switched to branch 'master'
[book@SERVER scripts_new]$ git merge modify

图示:

[book@SERVER scripts_new]$ git br -d hotfix modify

变基完成

1.3. 变基注意事项:

配置文件:
git config --global pull.rebase true